Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #line directive when running scripts #1069

Merged
merged 2 commits into from
Oct 31, 2022

Conversation

ngyikp
Copy link
Contributor

@ngyikp ngyikp commented Jul 31, 2022

According to https://www.michalkomorowski.com/2016/10/roslyn-how-to-create-custom-debuggable_27.html, we can add #line directive to let the debugger know where the exception occurs

Before, the debugger doesn't point to the exact line in the custom script:
before

After, now the line is highlighted:
after

According to https://www.michalkomorowski.com/2016/10/roslyn-how-to-create-custom-debuggable_27.html, we can add `#line` directive to let the debugger know where the exception occurs
@Miepee
Copy link
Contributor

Miepee commented Jul 31, 2022

Can you add this to the CLI as well?

@VladiStep
Copy link
Member

🤯

I've tried to make it work like this some time ago, but I've only managed to make it emit a debug info, so you can see the stacktrace of an exception in the error message box, and the code context (see "Locals" window at the bottom of the screenshots).

@ngyikp
Copy link
Contributor Author

ngyikp commented Jul 31, 2022

Added to CLI as well

Before:

Trying to load file: 'C:\Users\User\Desktop\game.ios'
System.NullReferenceException: Object reference not set to an instance of an object.
   at Submission#0.addObjCustomDog() in :line 61
   at Submission#0.<<Initialize>>d__0.MoveNext() in :line 23
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptStateTaskExtensions.GetEvaluationResultAsync[T](Task`1 task)
   at UndertaleModCli.Program.RunCSharpCode(String code, String scriptFile) in C:\Users\User\source\repos\UndertaleModTool\UndertaleModCli\Program.cs:line 724

After:

Trying to load file: 'C:\Users\User\Desktop\game.ios'
System.NullReferenceException: Object reference not set to an instance of an object.
   at Submission#0.addObjCustomDog() in C:\Users\User\source\repos\UndertaleModTool\UndertaleModTool\Scripts\Community Scripts\AddObjCustomDog.csx:line 61
   at Submission#0.<<Initialize>>d__0.MoveNext() in C:\Users\User\source\repos\UndertaleModTool\UndertaleModTool\Scripts\Community Scripts\AddObjCustomDog.csx:line 23
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptStateTaskExtensions.GetEvaluationResultAsync[T](Task`1 task)
   at UndertaleModCli.Program.RunCSharpCode(String code, String scriptFile) in C:\Users\User\source\repos\UndertaleModTool\UndertaleModCli\Program.cs:line 724

@Grossley Grossley merged commit c3761a7 into UnderminersTeam:master Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants